﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace learncore2
{
    public class URLPath
    {
        public string APIVersion { get; set; }
        public string Controller { get; set; }
        public string Method { get; set; }

        public URLPath(string v,string c,string m)
        {
            APIVersion = v;
            Controller = c;
            Method = m;
        }

        public static URLPath ConvertToUrlPath(string s)
        {
            if (s.EndsWith(@"/"))
            {
                s = s + "/";
            }
            var c = s.Split(@"/");
            Console.WriteLine(c.Length);
            try
            {
                if (c.Length >= 3)
                {

                    if (c.Length == 7)
                    {
                        return new URLPath(c[2], c[3], c[4]);
                    }
                    else
                    {
                        return new URLPath(c[2], c[3], "Get");
                    }

                }
            }
            catch (Exception e)
            {
                return null;
            }
            
            return null;
        }
    }
}
